﻿
#include <stdio.h>
#include "KcCore.h"

// 可以在编译环境定义KCCM_FUNCTION直接使用KccMain的函数
static KCCORE_FUNCTION mKCCF;
KCCORE_FUNCTION* coreGetKccf(void) {
	return &mKCCF;
}

#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
#include "KccMain.h"
#endif

int coreVersion(int level, int* dateTime, int* version) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
    return KccmVersion(level, dateTime, version);
#else
    int result = coreFunction(&mKCCF);
    if (result == RESULT_OK){
        return mKCCF.Version(level, dateTime, version);
    }
    return RESULT_NO_INIT;
#endif
}
int coreSetCallback(KCCORE_CALLBACK* callback, void* heap, int length) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmSetCallback(callback, heap, length);
#else
	return (mKCCF.SetCallback != NULL) ? mKCCF.SetCallback(callback, heap, length) : RESULT_NO_INIT;
#endif
}
int coreCommand(int argc, char** argv, int* state, void(*callback)(int, char*)) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return (mKCCF.Command != NULL) ? mKCCF.Command(argc, argv, state, callback) : RESULT_NO_INIT;
#else
	return (mKCCF.Command != NULL) ? mKCCF.Command(argc, argv, state, callback) : RESULT_NO_INIT;
#endif
}
int coreFileInfo(int* setData, char* fileName) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileInfo(setData, fileName);
#else
	return (mKCCF.FileInfo != NULL) ? mKCCF.FileInfo(setData, fileName) : RESULT_NO_INIT;
#endif
}
int coreFileControl(int effTyp, int track, int setTyp) {                      // core控制 线程安全
	return coreFileSetup(effTyp, track, setTyp, 0, NULL, NULL);
}
int coreFileSetup(int effTyp, int track, int setTyp, int setOffset, int* ramBase, char* fileName) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileSetup(effTyp, track, setTyp, setOffset, ramBase, fileName);
#else
	return (mKCCF.FileSetup != NULL) ? mKCCF.FileSetup(effTyp, track, setTyp, setOffset, ramBase, fileName) : RESULT_NO_INIT;
#endif
}
int coreFileData(int effTyp, int track, int mode, void* inDat, int length) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileData(effTyp, track, mode, inDat, length);
#else
	return (mKCCF.FileData != NULL) ? mKCCF.FileData(effTyp, track, mode, inDat, length) : RESULT_NO_INIT;
#endif
}
int coreFileAudio(int effTyp, int track, int mode, void* inDat) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileAudio(effTyp, track, mode, inDat) ;
#else
	return (mKCCF.FileAudio != NULL) ? mKCCF.FileAudio(effTyp, track, mode, inDat) : RESULT_NO_INIT;
#endif
}
int coreFileVideo(int effTyp, int track, int mode, int value, void* env, void* object) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileVideo(effTyp, track, mode, value, env, object);
#else
	return (mKCCF.FileVideo != NULL) ? mKCCF.FileVideo(effTyp, track, mode, value, env, object) : RESULT_NO_INIT;
#endif
}
int coreFileMuxer(int medTyp, char* muxFile, char* videoFile, char* audioFile, int* values) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmFileMuxer(medTyp, muxFile, videoFile, audioFile, values);
#else
	return (mKCCF.FileMuxer != NULL) ? mKCCF.FileMuxer(medTyp, muxFile, videoFile, audioFile, values) : RESULT_NO_INIT;
#endif
}
int coreColorFormat(int outFmt, char* outData, int inFmt, char* inData, int width, int height) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmColorFormat(outFmt, outData, inFmt, inData, width, height);
#else
	return (mKCCF.ColorFormat != NULL) ? mKCCF.ColorFormat(outFmt, outData, inFmt, inData, width, height) : RESULT_NO_INIT;
#endif
}

int audioEffGetInfo(int effn, int type) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffGetInfo(effn, type);
#else
	return (mKCCF.AudEffGetInfo != NULL) ? mKCCF.AudEffGetInfo(effn, type) : 0;
#endif
}

int audioEffOutput(int effn) {								// 输出音频块 返回chFlag    
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffOutput(effn);
#else
	return (mKCCF.AudEffOutput != NULL) ? mKCCF.AudEffOutput(effn) : false;
#endif
}
// 返回		返回flase需要继续重试
// filNum	多路输入通过filNum区分，话筒输入filNum=-1
// waveInfo	KCC_WAVE_INFO结构
bool audioEffInput(int effn, int filIdx, void* waveInfo) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffInput(effn, filIdx, waveInfo);
#else
	return (mKCCF.AudEffInput != NULL) ? mKCCF.AudEffInput(effn, filIdx, waveInfo) : false;
#endif
}
// length	指令文字长度，最大0x1000-1(指令文字写入ramBase)
bool audioEffCommand(int effn, int length) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffCommand(effn, length);
#else
	return (mKCCF.AudEffCommand != NULL) ? mKCCF.AudEffCommand(effn, length) : false;
#endif
}
// sampRate	输出采样率
// filMax	输入的文件数量
// mic		话筒输入
bool audioEffConfig(int effn, int sampRate, int filMax, bool mic) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffConfig(effn, sampRate, filMax, mic);
#else
	return (mKCCF.AudEffConfig != NULL) ? mKCCF.AudEffConfig(effn, sampRate, filMax, mic) : false;
#endif
}
// 关闭及回收
bool audioEffTerminate(int effn) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffTerminate(effn);
#else
	return (mKCCF.AudEffTerminate != NULL) ? mKCCF.AudEffTerminate(effn) : false;
#endif
}
// chQty	输出的通道数
// sampRate	每次输出的采样长度
// ramBase	提供 0x1000字节用于装载指令文字 
//			提供 两组 chQty * sampLeng * 8 字节用于音效处理及输出
bool audioEffInitia(int effn, int chQty, int blockSize, int* ramBase) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffInitia(effn, chQty, blockSize, ramBase);
#else
	return (mKCCF.AudEffInitia != NULL) ? mKCCF.AudEffInitia(effn, chQty, blockSize, ramBase) : false;
#endif
}
void* audioEffSoundCard(void) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmAudEffSoundCard();
#else
	return (mKCCF.AudEffSoundCard != NULL) ? mKCCF.AudEffSoundCard() : NULL;
#endif
}


int audioEffectSetup(int effTyp, int track, int setTyp, int setOffset, void* ramBase) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmEffectSetup(effTyp, track, setTyp, setOffset, ramBase);
#else
	return (mKCCF.EffectSetup != NULL) ? mKCCF.EffectSetup(effTyp, track, setTyp, setOffset, ramBase) : RESULT_NO_INIT;
#endif
}
int audioEffectData(int effTyp, int track, void* object) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmEffectData(effTyp, track, object);
#else
	return (mKCCF.EffectData != NULL) ? mKCCF.EffectData(effTyp, track, object) : RESULT_NO_INIT;
#endif
}
int audioLevelFft(int track, int mode, void* object) {
#if (KCCM_FUNCTION != 0)                                    // 如果定义了直接使用KccMain
	return KccmLevelFft(track, mode, object);
#else
	return (mKCCF.LevelFft != NULL) ? mKCCF.LevelFft(track, mode, object) : RESULT_NO_INIT;
#endif
}
